{% extends "templates/atnet_base.html" %}

{% block csslink %}
		{{ super() }}
<script src="/media/js/jquery.js"></script>

{% include 'templates/includes_datatable.html' %}
{% include 'templates/includes_jquery_ui.html' %}
<script src="/media/js/form_popup.js"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	var wasAction = false;
	
	$('#tenement').dataTable({
		"bPaginate": false,
		"bLengthChange": false,
		"bFilter": true,
		"bSort": false,
		"bInfo": false,
		"bAutoWidth": false,
		"oLanguage": {
            "sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
        },
		"bProcessing": true,
		"sAjaxSource": "{{ uri_for('immeuble', imm_id=id, command='json') }}",
		"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
			$('td:eq(0)', nRow).html('<b>' + aData[0] + '</b>:');
		},
	});
	
	$('#edit').live('click', function(){
		$(this).LaunchPopup(
			{
				TableId: '#tenement',
				DivId: '#dialog-form',
				FormId: '#generated-form',
				UrlForm: "{{ uri_for('immeuble', imm_id=id, command='edit') }}",
				Mode: 'edit',
				Title: '{{ _("Edit tenement") }}'
			}
		)
	});
	
	$('#add').live('click', function(){
		$(this).LaunchPopup(
			{
				TableId: '#tenement',
				DivId: '#dialog-form',
				FormId: '#generated-form',
				UrlForm: "{{ uri_for('immeuble', imm_id=id, command='add') }}",
				Mode: 'add',
				Title: '{{ _("Add tenement") }}'
			}
		)
	});
});
</script>
{% endblock %}

{% block title %} 
	{{ title }}
{% endblock %}

{% block header %}
{{ header }}
{% endblock %}

{% block login%}
{% if show_login %}
{{ super() }}
{% endif %}
{% endblock%}

{% block navigation %}
{{ super() }}
{% endblock %}

{% block section_menu %}
{% include 'templates/includes_creation_menu.html' %}
{% endblock %}

{% block main_content %}
<p>
	{% if show_edit %}
	<a href="javascript:void(0);" id="add">{{ _('Add new') }}</a>
	{% endif %}
	<fieldset>
    <legend>{{ legend }}</legend>
    	<div id="demo">
		<table cellpadding="0" cellspacing="0" border="0" class="display" id="tenement" width="100%">
			<thead>
				<tr>
					<th></th>
					<th></th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td colspan="2" class="dataTables_empty">{{ _('Loading data from server') }}</td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<th></th>
					<th></th>
				</tr>
			</tfoot>
		</table>
		</div>
	{% if show_edit %}
	<p><a href="javascript:void(0);" id="edit">{{ _('Edit') }}</a></p>
	{% endif %}
	</fieldset>
	{% include 'templates/includes_popup_form.html' %}
</p>
<script>
$(function() {	
	var user_lang = "{{ app_user.lang }}";
	if (user_lang == "en") { user_lang = "en-GB"};
	$.datepicker.setDefaults( $.datepicker.regional[ user_lang ] );
	
	$("#bulding_completion_date").live("focus", function() {
	    $(this).datepicker({
	        inline: true,
	    });
	});
	$("#building_cert_date").live("focus", function() {
	    $(this).datepicker({
	        inline: true,
	    });
	});
	$("#building_permit_date").live("focus", function() {
	    $(this).datepicker({
	        inline: true,
	    });
	});
});
</script>			
{% endblock %}
